﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Ooaavee.TestTools;

namespace UnitTests.Ooaavee.TestTools
{
    [TestClass]
    public class ExtendedTestContextTest : TestBase
    {
        /// <summary>
        /// Tests TestContext property.
        /// </summary>
        [TestMethod]
        public void TestContextTest()
        {
            Assert.AreEqual(base.TestContext, base.ExtendedTestContext.TestContext, "Could not found TextContext.");
        }

        /// <summary>
        /// Tests TestMethod property.
        /// </summary>
        [TestMethod]
        public void TestMethodTest1()
        {
            Assert.AreEqual("TestMethodTest1", base.ExtendedTestContext.TestMethod.Name, "Could not found current test method.");
        }

        /// <summary>
        /// Tests TestMethod property.
        /// </summary>
        [TestMethod]
        public void TestMethodTest2()
        {
            Assert.AreNotEqual("TestMethodTest1", base.ExtendedTestContext.TestMethod.Name, "Found wrong test method..");
        }

        /// <summary>
        /// Tests IsParameterizedTest property.
        /// </summary>
        [TestMethod]
        public void IsParameterizedTestTest1()
        {
            Assert.IsFalse(base.ExtendedTestContext.IsParameterizedTest,
                           "This test method isn't parameterized test, because it's not marked with the TestParametersAttribute.");
        }

        /// <summary>
        /// Tests IsParameterizedTest property.
        /// </summary>
        [TestParameters]
        [TestMethod]
        public void IsParameterizedTestTest2()
        {
            Assert.IsTrue(base.ExtendedTestContext.IsParameterizedTest,
                          "This test method is parameterized test, because it's marked with the TestParametersAttribute.");
        }

        /// <summary>
        /// Tests TestParameters property.
        /// </summary>
        [TestMethod]
        public void TestParametersTest1()
        {
            Assert.AreEqual(0, base.ExtendedTestContext.TestParameters.Count, "An empty collection was expected.");
        }

        /// <summary>
        /// Tests TestParameters property.
        /// </summary>
        [TestParameters]
        [TestMethod]
        public void TestParametersTest2()
        {
            Assert.AreEqual(0, base.ExtendedTestContext.TestParameters.Count,
                            "An empty collection was expected, because no parameters were introduced.");
        }

        /// <summary>
        /// Tests TestParameters property.
        /// </summary>
        [TestParameters("First parameter", "Second parameter", 3, 4, null)]
        [TestMethod]
        public void TestParametersTest3()
        {
            Assert.AreEqual(5, base.ExtendedTestContext.TestParameters.Count, "Invalid number of parameters.");
            Assert.AreEqual("First parameter", base.ExtendedTestContext.TestParameters[0], "Invalid parameter.");
            Assert.AreEqual("Second parameter", base.ExtendedTestContext.TestParameters[1], "Invalid parameter.");
            Assert.AreEqual(3, base.ExtendedTestContext.TestParameters[2], "Invalid parameter.");
            Assert.AreEqual(4, base.ExtendedTestContext.TestParameters[3], "Invalid parameter.");
            Assert.AreEqual(null, base.ExtendedTestContext.TestParameters[4], "Invalid parameter.");
        }

        /// <summary>
        /// Tests TestParameters property.
        /// </summary>
        [MyCustomTestParameters]
        [TestMethod]
        public void TestParametersTest4()
        {
            Assert.AreEqual(5, base.ExtendedTestContext.TestParameters.Count, "Invalid number of parameters.");
            Assert.AreEqual("Hello Test Method: UnitTests.Ooaavee.TestTools.ExtendedTestContextTest.TestParametersTest4", base.ExtendedTestContext.TestParameters[0], "Invalid parameter.");
            Assert.AreEqual(1234567890, base.ExtendedTestContext.TestParameters[1], "Invalid parameter.");
            Assert.AreEqual(-1.2345m, base.ExtendedTestContext.TestParameters[2], "Invalid parameter.");
            Assert.AreEqual(null, base.ExtendedTestContext.TestParameters[3], "Invalid parameter.");
            Assert.AreEqual(DateTime.Now.Date, base.ExtendedTestContext.TestParameters[4], "Invalid parameter.");
        }
    }
}
